package remoting.channel;

import common.model.MagicUrl;
import remoting.store.DataStore;
import threadpools.ThreadPool;

public class ChannelHandlers {

  private static ChannelHandlers INSTANCE = new ChannelHandlers();

  protected ChannelHandlers() {
  }

  public static ChannelHandler wrap(ChannelHandler handler, MagicUrl url, ThreadPool threadPool) {
    return ChannelHandlers.getInstance().wrapInternal(handler, url, threadPool);
  }

  protected static ChannelHandlers getInstance() {
    return INSTANCE;
  }

  static void setTestingChannelHandlers(ChannelHandlers instance) {
    INSTANCE = instance;
  }

  protected ChannelHandler wrapInternal(ChannelHandler handler, MagicUrl url,
      ThreadPool threadPool) {
    return new MultiMessageHandler(new HeartbeatHandler(new AllChannelHandler(handler, url,
        threadPool)));
  }
}
